package com.tzxscu.hosdrool.webapi;


import com.alibaba.fastjson.JSONObject;
import com.tzxscu.hosdrool.models.BillItems;
import com.tzxscu.hosdrool.models.BillItemsBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.tzxscu.hosdrool.drools.droolsapi;
import com.tzxscu.hosdrool.drools.droolsapi_2;

import javax.xml.ws.Response;
import java.util.ArrayList;
import java.util.List;

@Controller

public class webapi {
    @RequestMapping(value = "/insur",method = RequestMethod.POST)
    @ResponseBody
    public static String MyApi(String jsontxt){
        jsontxt="[{'item_code':'123456','item_name':'测试项目1','amount':2,'billing_datetime':'2021-05-01'}"+
                ",{'item_code':'1234567','item_name':'测试项目2','amount':1,'billing_datetime':'2021-04-01'}]";

        List<BillItems> list = JSONObject.parseArray(jsontxt,BillItems.class);
/*        System.out.println(list);

        BillItems billItem =new BillItems("123456",2,"2021-05-01","测试条码");
        BillItems billItem2 =new BillItems("1234567",1,"2021-06-01","测试条码2");
        List<BillItems> billItems = new ArrayList<BillItems>();
        billItems.add(billItem);
        billItems.add(billItem2);
        System.out.println(billItems);*/
        String retmsg = droolsapi.drools(list);

        return retmsg;
    }


    @RequestMapping(value = "/ins",method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public static String MyApi2(@RequestBody List<BillItems> list){
      /* jsontxt="[{'item_code':'123456','item_name':'测试项目1','amount':2,'billing_datetime':'2021-05-01'}"+
                ",{'item_code':'1234567','item_name':'测试项目2','amount':1,'billing_datetime':'2021-04-01'}]";
       */

       // List<BillItems> list = JSONObject.parseArray(jsontxt,BillItems.class);
    /*   System.out.println(list);

        BillItems billItem =new BillItems("123456",2,"2021-05-01","测试条码");
        BillItems billItem2 =new BillItems("1234567",1,"2021-06-01","测试条码2");

        List<BillItems> billItems = new ArrayList<BillItems>();
        billItems.add(billItem);
        billItems.add(billItem2);
        System.out.println(billItems);*/
        String retmsg = droolsapi_2.drools(list);

        return retmsg;
    }


}
